package com.bawei.a2010douyin.base.rx;

import android.os.Build;
import android.util.Log;

import com.bawei.a2010douyin.base.utils.ConstantUtils;
import com.bawei.a2010douyin.entity.BaseResponse;
import com.bawei.a2010douyin.entity.VideoEntity;
import com.blankj.utilcode.util.Utils;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;

//转换基类
public class BaseFunc<T> implements Function<BaseResponse<T>, ObservableSource<T>>
{
    @Override
    public ObservableSource<T> apply(BaseResponse<T> tBaseResponse) throws Exception {
        if(tBaseResponse.getCode() != ConstantUtils.SUCESS_CODE){//失败
            return Observable.error(new BaseException(tBaseResponse.getCode(),tBaseResponse.getMessage()));
        }else{//成功
            return Observable.just(tBaseResponse.getData());
        }
    }
}
